package cn.edu.gues.infosystam.mapper;

import cn.edu.gues.infosystam.entity.Report;
import cn.edu.gues.infosystam.entity.Task;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 苏小小
 * @since 2020-06-11
 */
public interface ReportMapper extends BaseMapper<Report> {

    /**
     * 查询待填报任务
     * @param page
     * @param queryWrapper
     * @return
     */
    @Select("SELECT task.task_id, task.task_name, task.task_range, task.task_template, task.task_start, task.task_end, " +
            "task.task_state, task.deleted FROM task ${ew.customSqlSegment} ")
    IPage<Task> getReportTask(Page<?> page,@Param(Constants.WRAPPER) QueryWrapper<Task> queryWrapper);

    /**
     * 导出填报详情
     * @param taskId
     * @return
     */
    @Select("SELECT student.sno, student.sname, cclass.college, cclass.cname, report.task_id, report.report_id, " +
            "report.report_content FROM report INNER JOIN student ON (report.sno = student.sno and " +
            "student.deleted = 0) INNER JOIN cclass ON  student.cid = cclass.cid  WHERE report.task_id = #{taskId} and report.deleted = 0")
    List<Report> getReportAll(Integer taskId);

}
